<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="vue.js" type="text/javascript" charset="utf-8"></script>
    <style>
       
    </style>
</head>
<body>
   <section id="todoapp">
    <header class="header">
        <h1>小黑记事本</h1>
        <input v-model="inputValue" @keyup.enter="add" autofocus="autofocus" autocomplete="off" placeholder="请输入任务" class="new-todo">
    </header>
    <section class="main">
        <ul class="todo-list">
            <li class="todo" v-for="(item,index) in list">
                <div class="view">
                    <span class="index">{{ index+1 }}</span>
                    <label>{{item}}</label>  
                    <input type="button" class="destory" @click="remove(index)" value="x">
                </div>
            </li>
        </ul>
    </section>
    <footer class="footer">
         <span class="todo-count" v-show="list.length!=0">
             <strong>
                 {{list.length}}
             </strong>
             item left
         </span>
         <button class="clear-completed" @click="clean"v-show="list.length!=0" >Clean</button>
    </footer>
   </section>
   <footer class="info">

   </footer>
    <script> 
        // 列表结构可以通过v-for指令结合数据生成
        // v-on结合事件修饰符可以对事件进行限制，比如.enter
        // v-on在绑定事件时可以传递自定义参数
        // 通过v-model可以快速的设置和获取表单元素的值
        // 基于数据的开发模式
        var app= new Vue({ 
            el:"#todoapp",
            data:{
              list:[
                  "吃饭饭",
                  "睡觉觉",
                  "写代码"
              ],
              inputValue:"好好学习天天向上"
            },
            methods: {
                //添加
              add:function(){
                  this.list.push(this.inputValue);
              },
              //删除
              remove:function(index){
                console.log(index);
                this.list.splice(index,1);
              },
              clean:function(){
                this.list=[];
              }
            }, 
        });

    </script>
</body>
</html> 